 package xin.petstore.framework.web.validator;
 
 import xin.petstore.framework.cas.SessionUtils;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;

 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 @RequestMapping({"/generateImage"})
 @Controller
 public class GenerateImageController
 {
   private static final Logger logger = LoggerFactory.getLogger(GenerateImageController.class);
 
   @RequestMapping(method={org.springframework.web.bind.annotation.RequestMethod.GET})
   public void ImageCaptcha(HttpServletRequest request, HttpServletResponse response)
   {
     response.setHeader("Cache-Control", "no-store");
     response.setHeader("Pragma", "no-cache");
     response.setDateHeader("Expires", 0L);
     response.setContentType("image/jpeg");
     try
     {
       ServletOutputStream responseOutputStream = response.getOutputStream();
       ImageCodeEngine ice = new ImageCodeEngine();
       String rand = ice.genCode(responseOutputStream);
       SessionUtils.getSession().setAttribute("image_valid_code", rand);
 
       responseOutputStream.close();
     }
     catch (Exception e) {
       logger.error("Captcha image error\n ", e);
     }
   }
 }
